package cn.java76;

import java.io.*;
import java.net.Socket;
import java.util.zip.GZIPInputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;


public class HttpClient2 {

    public static void main(String[] args) throws Exception, IOException {
        Socket s = new Socket("www.ahflcp.com.cn", 80);
        InputStream in = s.getInputStream();
        OutputStream out = s.getOutputStream();

        PrintWriter pw = new PrintWriter(out);
        pw.println("GET http://www.ahflcp.com.cn/customization/lottery/kjls_ssq.html?cp=1  HTTP/1.1");
        //pw.println("HOST: www.bdqn.cn");
        pw.println("Host: www.ahflcp.com.cn");
        pw.println("Connection: keep-alive");
        pw.println("Cache-Control: max-age=0");
        pw.println("Upgrade-Insecure-Requests: 1");
        pw.println("User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36");
        pw.println("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");
        pw.println("Accept-Encoding: gzip, deflate");
        pw.println("Accept-Language: zh-CN,zh;q=0.9,zh-TW;q=0.8,en-US;q=0.7,en;q=0.6");
        pw.println("Cookie: _gscu_162213139=381028114wpk9w73; fcweb_session=\"gAJ9cQEu:1msbv2:HQVrLL2m0ZCF6x94IZXPuxDdQhk\"");

        pw.println();//空行
        pw.flush();
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        int b = 0;
        while ((b = in.read()) != -1) {
            bout.write(b);
        }
        System.out.println(bout.toByteArray().length + ">>>>>>>>>>>>");
        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
        GZIPInputStream gin = new GZIPInputStream(bin);
        FileOutputStream fos = new FileOutputStream("D:/1.html");
        int BUFFER = 10240;

        int count;
        byte data[] = new byte[BUFFER];
        while ((count = gin.read(data)) != -1) {
            fos.write(data, 0, count);
        }
        fos.close();


        s.close();
    }
}
